//
//
//  角码加工界面
//
//


import QtQuick

Item {
    id: cornerProcessWindowRoot
    width: rootWidth
    height: rootHeight /*- 150*/

    A_NumberKeyboard{
        id: cornerProcessKeyboard
        isDirectOverwrite: false
    }


    Component.onCompleted: {
        Cpp_PLC.QML_CurrentPage = 4;
        Cpp_PLC.write_Modbus_RTU_Hold_16(48,"2")
    }

    Text{
        anchors.horizontalCenter: cornerProcessWindowRoot.horizontalCenter
        anchors.top: cornerProcessWindowRoot.top
        anchors.topMargin: 10
        font.pixelSize: 40
        font.bold: true
        text: qsTr("角码加工界面")
    }

    // 机头角度选择
    MechineAngle{
        id: mechineAngleArea
        anchors.top: cornerProcessWindowRoot.top
        anchors.horizontalCenter: cornerProcessWindowRoot.horizontalCenter
    }

    Item{
        id: workAreaBack
        anchors.top: mechineAngleArea.bottom
        anchors.topMargin: -3
        anchors.horizontalCenter: cornerProcessWindowRoot.horizontalCenter
        width: cornerProcessWindowRoot.width
        height: 980

        Rectangle{
            anchors.fill: parent
            color: "transparent"
            // color: "red"
            border.width: 3
            border.color: "#F0F8FF"
        }

        A_Label{
            anchors.bottom: miniCornerLengthInput.top
            anchors.bottomMargin: 10
            anchors.horizontalCenter: miniCornerLengthInput.horizontalCenter
            labelWidth: 300
            labelHeight: 70
            label_Data: qsTr("角码最短料长")
            labelBack: "transparent"
            labelBorderColor: "transparent"
        }

        // A_TextInput{
        //     id: miniCornerLengthInput
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 90
        //     anchors.left: workAreaBack.left
        //     anchors.leftMargin: 200
        //     inputWidth: 300
        //     showData: Cpp_PLC.Corner_Min_Length

        //     onInputFinished: {
        //         // console.log("角码最短料长: "+ inputData)
        //         Cpp_PLC.write_Modbus_RTU_Hold_32(1292,inputData)
        //     }
        // }


        A_NumberInput{
            id: miniCornerLengthInput
            anchors.top: workAreaBack.top
            anchors.topMargin: 90
            anchors.left: workAreaBack.left
            anchors.leftMargin: 200
            inputWidth: 300
            text: Cpp_PLC.Corner_Min_Length
            keyboard: cornerProcessKeyboard

            onEditingFinished: function(value){
                Cpp_PLC.write_Modbus_RTU_Hold_32(1292,value)
            }

        }

        A_Label{
            anchors.bottom: materialLengthInput.top
            anchors.bottomMargin: 10
            anchors.horizontalCenter: materialLengthInput.horizontalCenter
            labelWidth: 300
            labelHeight: 70
            label_Data: qsTr("原 料 长 度")
            labelBack: "transparent"
            labelBorderColor: "transparent"
        }

        // A_TextInput{
        //     id: materialLengthInput
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 90
        //     anchors.right: workAreaBack.right
        //     anchors.rightMargin: 200
        //     inputWidth: 300
        //     showData: Cpp_PLC.Corner_Material_Length


        //     onInputFinished: {
        //         // console.log("原料长度: "+ inputData)
        //         Cpp_PLC.write_Modbus_RTU_Hold_32(1276,inputData)
        //     }
        // }

        A_NumberInput{
            id: materialLengthInput
            anchors.top: workAreaBack.top
            anchors.topMargin: 90
            anchors.right: workAreaBack.right
            anchors.rightMargin: 200
            inputWidth: 300
            text: Cpp_PLC.Corner_Material_Length
            keyboard: cornerProcessKeyboard

            onEditingFinished: function(value){
                Cpp_PLC.write_Modbus_RTU_Hold_32(1276,value)
            }

        }


        Rectangle{
            anchors.left: materialLengthInput.right
            anchors.verticalCenter: materialLengthInput.verticalCenter
            width: 174
            height: 150
            color: "transparent"
            visible: Cpp_PLC.Corner_Set_Err

            Text{
                anchors.centerIn: parent
                font.pixelSize: 40
                color: "red"
                text: qsTr("错误!!!")
            }

        }


        A_Label{
            anchors.bottom: cornerLengthInput.top
            anchors.bottomMargin: 10
            anchors.horizontalCenter: cornerLengthInput.horizontalCenter
            labelWidth: 300
            labelHeight: 70
            label_Data: qsTr("角码长度")
            labelBack: "transparent"
            labelBorderColor: "transparent"
        }

        // A_TextInput{
        //     id: cornerLengthInput
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 250
        //     anchors.left: workAreaBack.left
        //     anchors.leftMargin: 200
        //     inputWidth: 300
        //     showData: Cpp_PLC.Corner_Length

        //     onInputFinished: {
        //         // console.log("角码长度: "+ inputData)
        //         Cpp_PLC.write_Modbus_RTU_Hold_32(1272,inputData)
        //     }
        // }


        A_NumberInput{
            id: cornerLengthInput
            anchors.top: workAreaBack.top
            anchors.topMargin: 250
            anchors.left: workAreaBack.left
            anchors.leftMargin: 200
            inputWidth: 300
            text: Cpp_PLC.Corner_Length
            keyboard: cornerProcessKeyboard

            onEditingFinished: function(value){
                Cpp_PLC.write_Modbus_RTU_Hold_32(1272,value)
            }

        }


        A_Label{
            anchors.bottom: cornerSectionsInput.top
            anchors.bottomMargin: 10
            anchors.horizontalCenter: cornerSectionsInput.horizontalCenter
            labelWidth: 300
            labelHeight: 70
            label_Data: qsTr("角 码 段 数")
            labelBack: "transparent"
            labelBorderColor: "transparent"
        }

        // A_TextInput{
        //     id: cornerSectionsInput
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 250
        //     anchors.right: workAreaBack.right
        //     anchors.rightMargin: 200
        //     inputWidth: 300
        //     showData: Cpp_PLC.Corner_Set_Segments

        //     onInputFinished: {
        //         // console.log("角码段数: "+ inputData)
        //         Cpp_PLC.write_Modbus_RTU_Hold_16(228,inputData)
        //     }
        // }

        A_NumberInput{
            id: cornerSectionsInput
            anchors.top: workAreaBack.top
            anchors.topMargin: 250
            anchors.right: workAreaBack.right
            anchors.rightMargin: 200
            inputWidth: 300
            text: Cpp_PLC.Corner_Set_Segments
            keyboard: cornerProcessKeyboard

            onEditingFinished: function(value){
                Cpp_PLC.write_Modbus_RTU_Hold_16(228,value)
            }

        }


        A_Label{
            anchors.bottom: knifeCompensateInput.top
            anchors.bottomMargin: 10
            anchors.horizontalCenter: knifeCompensateInput.horizontalCenter
            labelWidth: 300
            labelHeight: 70
            label_Data: qsTr("刀  补")
            labelBack: "transparent"
            labelBorderColor: "transparent"
        }

        // A_TextInput{
        //     id: knifeCompensateInput
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 410
        //     anchors.left: workAreaBack.left
        //     anchors.leftMargin: 200
        //     inputWidth: 300
        //     showData: Cpp_PLC.Corner_Cut_Compensate

        //     onInputFinished: {
        //         // console.log("刀补: "+ inputData)
        //         Cpp_PLC.write_Modbus_RTU_Hold_32(1274,inputData)
        //     }
        // }

        A_NumberInput{
            id: knifeCompensateInput
            anchors.top: workAreaBack.top
            anchors.topMargin: 410
            anchors.left: workAreaBack.left
            anchors.leftMargin: 200
            inputWidth: 300
            text: Cpp_PLC.Corner_Cut_Compensate
            keyboard: cornerProcessKeyboard

            onEditingFinished: function(value){
                Cpp_PLC.write_Modbus_RTU_Hold_32(1274,value)
            }

        }


        A_Label{
            anchors.top: workAreaBack.top
            anchors.topMargin: 495
            anchors.left: workAreaBack.left
            anchors.leftMargin: 200
            labelWidth: 300
            labelBack: "transparent"
            labelBorderColor: "transparent"
            label_Data: qsTr("当 前 段 数")
        }

        A_Label{
            anchors.top: workAreaBack.top
            anchors.topMargin: 570
            anchors.left: workAreaBack.left
            anchors.leftMargin: 200
            labelBorderColor: "#F0F8FF"
            labelWidth: 300
            labelBack: "black"
            label_FontColor: "aqua"
            label_Data: Cpp_PLC.Corner_Current_Segments
        }

        A_Button{
            anchors.top: workAreaBack.top
            anchors.topMargin: 570
            anchors.right: workAreaBack.right
            anchors.rightMargin: 350
            contentText_Data: qsTr("段数清空")
            // contentText_Fontsize: 40

            onButtonPressed: {
                // console.log("清空段数按下")
                Cpp_PLC.write_Modbus_RTU_Coils(106,"1")
            }

            onButtonReleased: {
                // console.log("清空段数松开")
                Cpp_PLC.write_Modbus_RTU_Coils(106,"0")
            }

        }

        A_Label{
            anchors.top: workAreaBack.top
            anchors.topMargin: 655
            anchors.left: workAreaBack.left
            anchors.leftMargin: 200
            labelWidth: 300
            labelBack: "transparent"
            labelBorderColor: "transparent"
            label_Data: qsTr("累 计 段 数")
        }

        A_Label{
            anchors.top: workAreaBack.top
            anchors.topMargin: 730
            anchors.left: workAreaBack.left
            anchors.leftMargin: 200
            labelBorderColor: "#F0F8FF"
            labelWidth: 300
            labelBack: "black"
            label_FontColor: "aqua"
            label_Data: Cpp_PLC.Corner_Worked_Segments
        }

        A_Button{
            anchors.top: workAreaBack.top
            anchors.topMargin: 730
            anchors.right: workAreaBack.right
            anchors.rightMargin: 350
            contentText_Data: qsTr("段数清空")
            // contentText_Fontsize: 40

            onButtonPressed: {
                // console.log("清空段数按下")
                Cpp_PLC.write_Modbus_RTU_Coils(107,"1")
            }

            onButtonReleased: {
                // console.log("清空段数松开")
                Cpp_PLC.write_Modbus_RTU_Coils(107,"0")
            }

        }


        // Item{
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 800
        //     anchors.horizontalCenter: workAreaBack.horizontalCenter
        //     width: workAreaBack.width
        //     height: 170
        //     visible:false

        //     A_Label{
        //         anchors.top: parent.top
        //         // anchors.topMargin:
        //         anchors.horizontalCenter: parent.horizontalCenter
        //         labelWidth: 300
        //         label_Data: "料高测量值"
        //         labelBorderColor: "transparent"
        //         labelBack: "transparent"
        //     }

        //     A_Label{
        //         anchors.top: parent.top
        //         anchors.topMargin: 70
        //         anchors.horizontalCenter: parent.horizontalCenter
        //         labelBorderColor: "#F0F8FF"
        //         labelWidth: 300
        //         labelBack: "black"
        //         label_FontColor: "aqua"
        //     }

        //     A_Button{
        //         anchors.top: parent.top
        //         anchors.topMargin: 70
        //         anchors.left: parent.left
        //         anchors.leftMargin: 120

        //         contentText_Data: "误差修正"
        //         contentText_Fontsize: 40

        //         onButtonPressed: {
        //             console.log("误差修正按下")
        //         }

        //         onButtonReleased: {
        //             console.log("误差修正松开")
        //         }
        //     }

        //     Rectangle{
        //         anchors.top: parent.top
        //         anchors.topMargin: 70
        //         anchors.right: parent.right
        //         anchors.rightMargin: 320
        //         width: 30
        //         height: 70
        //         radius: 10
        //         border.width: 1
        //         border.color: "#F0F8FF"
        //         color: "black"

        //     }

        //     A_Button{
        //         anchors.top: parent.top
        //         anchors.topMargin: 70
        //         anchors.right: parent.right
        //         anchors.rightMargin: 120
        //         contentText_Data: "测  高"
        //         contentText_Fontsize: 40

        //         onButtonPressed: {
        //             console.log("测高按钮按下")
        //         }

        //         onButtonReleased: {
        //             console.log("测高按钮松开")
        //         }
        //     }
        // }
    }

    Item{
        id: buttonAreaBack
        anchors.top: workAreaBack.bottom
        anchors.horizontalCenter: cornerProcessWindowRoot.horizontalCenter
        width: cornerProcessWindowRoot.width
        height: 155

        Rectangle{
            anchors.fill: parent
            color: "transparent"
            border.width: 3
            border.color: "#000000"
        }

        A_Button{
            anchors.left: buttonAreaBack.left
            anchors.leftMargin: 20
            anchors.verticalCenter: buttonAreaBack.verticalCenter
            buttonWidth: 150
            buttonHeight: 90
            contentText_Data: qsTr("左  移")
            // contentText_Fontsize: 40

            onButtonPressed: {
                // console.log("左移按下")
                Cpp_PLC.write_Modbus_RTU_Coils(21,"1")
            }

            onButtonReleased: {
                // console.log("左移松开")
                Cpp_PLC.write_Modbus_RTU_Coils(21,"0")
            }
        }

        A_Button{
            anchors.left: buttonAreaBack.left
            anchors.leftMargin: 200
            anchors.verticalCenter: buttonAreaBack.verticalCenter
            buttonWidth: 150
            buttonHeight: 90
            contentText_Data: qsTr("右  移")
            // contentText_Fontsize: 40

            onButtonPressed: {
                // console.log("右移按下")
                Cpp_PLC.write_Modbus_RTU_Coils(22,"1")
            }

            onButtonReleased: {
                // console.log("右移松开")
                Cpp_PLC.write_Modbus_RTU_Coils(22,"0")
            }
        }

        A_Button{
            anchors.left: buttonAreaBack.left
            anchors.leftMargin: 380
            anchors.verticalCenter: buttonAreaBack.verticalCenter
            buttonWidth: 150
            buttonHeight: 90
            contentText_Data: qsTr("定  位")
            // contentText_Fontsize: 40

            onButtonPressed: {
                // console.log("定位按下")
                Cpp_PLC.write_Modbus_RTU_Coils(24,"1")
            }

            onButtonReleased: {
                // console.log("定位松开")
                Cpp_PLC.write_Modbus_RTU_Coils(24,"0")
            }
        }


    }



}
